package com.caiheng.api.service.estate.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.estate.PropertyUserMapper;
import com.caiheng.api.entity.estate.PropertyUser;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import com.caiheng.api.service.estate.PropertyUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 商家的管理用户wxuser的用户Service业务层处理
 *
 * @author ruoyi
 * @date 2022-08-20
 */
@Service
public class PropertyUserServiceImpl extends BaseServiceImpl<PropertyUserMapper, PropertyUser> implements PropertyUserService {

    @Resource
    private PropertyUserMapper propertyUserMapper;

    @Override
    public PropertyUser getPropertyUser(int userId) {
        QueryWrapper<PropertyUser> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("state",1);
        qw.last("limit  1");
        return propertyUserMapper.selectOne(qw);
    }

    @Override
    public PropertyUser getPropertyByUser(int userId, int propertyId) {
        QueryWrapper<PropertyUser> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("property_id",propertyId);
        qw.eq("state",1);
        qw.last("limit  1");
        return propertyUserMapper.selectOne(qw);
    }

    @Override
    public PropertyUser getPropertyManagerByUser(int propertyId, int isManager) {
        QueryWrapper<PropertyUser> qw = new QueryWrapper<>();
        qw.eq("property_id",propertyId);
        qw.eq("state",1);
        qw.eq("is_manager",isManager);
        qw.last("limit  1");
        return propertyUserMapper.selectOne(qw);
    }

    @Override
    public PropertyUser getCheckHolidayManager(int propertyId, int userId) {
        QueryWrapper<PropertyUser> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        if(propertyId > 0){
            qw.eq("property_id",propertyId);
        }
        qw.eq("state",1);
        qw.eq("is_check_holiday",1);
        qw.last("limit  1");
        return propertyUserMapper.selectOne(qw);
    }

    @Override
    public List<PropertyUser> selectPropertyUserList(Map<String, Object> map) {
        return propertyUserMapper.selectPropertyUserList(map);
    }
}
